//
// Created by liushuai on 19-8-4.
//
#include "next.h"
void next(string& pattern,vector<int>& n){
    int i = 0,j = -1;
    n[0] = -1;
    while (i < pattern.length())
    {
        if (j == -1 || pattern[i] == pattern[j])
        {
            ++i;
            ++j;
            n[i] = j;
        }
        else
            j = n[j];
    }

}
